<template>
  <div  style="font-size: 12px; line-height: 60px; display: flex">
    <div style="flex:1;font-size: 20px">
      <span :class="collapseBtnClass" style="cursor: pointer;font-size: 18px" @click="collapse"></span>
      <!--面包屑-->
      <el-breadcrumb separator="/" style="display: inline-block;margin-left: 10px">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item
            :to="{ path: item.path }"
            v-for="item in breadcrumbList"
            :key="item.path"
        >{{ item.meta.name }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!--下拉框-->
    <el-dropdown style="width: 150px; cursor: pointer; text-align: right">
        <!--头像用户名-->
      <div style="display: inline-block">
        <img :src="user.avatarUrl" alt=""
             style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px">
        <span>{{ user.nickname }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
      </div>
      <el-dropdown-menu slot="dropdown" style="width: 100px;text-align: center">
        <el-dropdown-item>
          <router-link to="/person" style="text-decoration: none">个人信息</router-link>
        </el-dropdown-item>
        <el-dropdown-item>
          <span style="text-decoration: none" @click="logout">退出</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  props:{
    collapseBtnClass: String,
    collapse:Function,
    user:Object
  },
  data(){
    return{
      breadcrumbData: {
        path:[]
      },
      // user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  computed:{
    //动态面包屑
    breadcrumbList(){
      // console.log(this.$route.matched)
      // this.$route.matched.forEach(item=>{
      //   this.breadcrumbData.path.push(item.path)
      // })
      // console.log(this.breadcrumbData)
      return this.$route.matched

    }
  },
  created() {
    // console.log(this.user)
  },
  methods:{
    logout() {
      this.$router.push("/login")
      localStorage.removeItem("user")
      this.$message.success("退出成功")
    }
  }
}
</script>

<style scoped>

</style>